<template>
  <div class="demo">
      <h2>学生名字:{{myName}}</h2>
      <h2>学生年龄:{{age}}</h2>
    <!-- <button @click="sendStudentName">把学生名给App</button>
    <button @click="unbind">解绑shijian事件</button>
    <button @click="sendToSchool">把学生名和学校组建</button> -->
  </div>
</template>

<script>
import pubsub from 'pubsub-js'
export default {
    name:'StudentS',
    data(){
        return {
            msg:"自我介绍",
            age:'66',
            myName:"123"
        }
    },
    mounted() {
        // 订阅
        this.pubid =  pubsub.subscribe('hello',function(msg,data){
            // 这里要注意的是，msg是订阅的hello，第二个参数才是真正传递的数据
            console.log('回执',msg,data);
        })
    },
    beforeDestroy() {
        // 销毁
        pubsub.unsubscribe(this.pubid)
    },
}
</script>


<style scoped>
    .demo{
        background-color: yellow;
    }
</style>